
#include "StdAfx.h"
#include "SpeakerVolumeControlProxy.h"

CSpeakerVolumeControlProxy::CSpeakerVolumeControlProxy(int VolumeType)
: m_SpeakerVolume(VolumeType)//: m_SpeakerVolume(VOLUME_SPEAKER)
{
	m_nMinVolume = m_SpeakerVolume.GetMinimalVolume();
	m_nMaxVolume = m_SpeakerVolume.GetMaximalVolume();

	m_SpeakerVolume.RegisterNotificationSink(SpeakerVolumeChangedProc, reinterpret_cast<DWORD>(this));
}

CSpeakerVolumeControlProxy::~CSpeakerVolumeControlProxy(void)
{
}

BOOL CSpeakerVolumeControlProxy::CanControl(VOLUME_CONTROL Control)
{
	return TRUE;
}

void CSpeakerVolumeControlProxy::GetVolumeRange(int& nMin, int& nMax)
{
	nMin = m_nMinVolume;
	nMax = m_nMaxVolume;
}

BOOL CSpeakerVolumeControlProxy::IsMute()
{
	return m_SpeakerVolume.GetMute();
}

BOOL CSpeakerVolumeControlProxy::SetMute(BOOL bMute)
{
	if(bMute)
		m_SpeakerVolume.SetMute(true);
	else
		m_SpeakerVolume.SetMute(false);

	return TRUE;
}

int CSpeakerVolumeControlProxy::GetVolume()
{
	return m_SpeakerVolume.GetCurrentVolume();
}

BOOL CSpeakerVolumeControlProxy::SetVolume(int nVolume, BOOL bChanging)
{
	m_SpeakerVolume.SetCurrentVolume(nVolume);

	return TRUE;
}

void CALLBACK CSpeakerVolumeControlProxy::SpeakerVolumeChangedProc(CVolumeControl *pVolumeControl, DWORD dwVolumeType, DWORD dwChangeType, DWORD dwUserValue)
{
	CSpeakerVolumeControlProxy* pThis = reinterpret_cast<CSpeakerVolumeControlProxy*>(dwUserValue);

	if(pThis->m_pNotifyProc == NULL)
		return;

	if(dwChangeType == CHANGE_VOLUME)
	{
		pThis->m_pNotifyProc(pThis, VC_VOLUME, pThis->m_dwUserData);
	}
	else
	{
		pThis->m_pNotifyProc(pThis, VC_MUTE, pThis->m_dwUserData);
	}
}